﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using EPiServer.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PageTypeBuilder;
using TemplateFoundation.Configuration;
using TemplateFoundation.Core;
using TemplateFoundation.Tests.Environment;
using TemplateFoundation.Tests.PageTypes;

namespace TemplateFoundation.Tests.UnitTests.Core
{
    [TestClass]
    public class PageFactoryGetPagesByPageType
    {
        [TestMethod]
        public void TestGettingPagesBySinglePageType()
        {
            var startCount = PageFactory.Instance.GetPagesByType(typeof (StandardPage), true).Count;

            PageStructure.CreateStandardPages("Standard page", PageReference.RootPage, 20);

            Assert.IsTrue(
                PageFactory.Instance.GetPagesByType(typeof(StandardPage), true).Count == startCount + 20,
                "Did not get 20 pages as expected");
        }

        [TestMethod]
        public void TestGettingPagesByMultiplePageTypes()
        {
            var startCount = PageFactory.Instance.GetPagesByType(new[] { typeof(StandardPage), typeof(ArticlePage) }, true).Count;

            PageStructure.CreateStandardPages("Standard page", PageReference.RootPage, 20);

            Settings.Instance.DisableDateFolderSorting = true;
            Settings.Instance.NewsContainer = PageStructure.CreateNewsContainer("Articles for TestGettingPagesByMultiplePageTypes test");

            PageStructure.CreateArticles(10, true);

            var pages = PageFactory.Instance.GetPagesByType(new [] { typeof(StandardPage), typeof(ArticlePage) },true);

            Assert.IsTrue(pages.Count==startCount + 30, "Did not get 30 pages as expected");
        }
    }
}
